<template>
  <div id="noticeSearch">
    <el-card v-show="props.showSearch" shadow="never">
      <el-form ref="queryFormRef" :inline="true" :model="queryParams">
        <el-row>
          <el-form-item label="关键词" prop="keyword">
            <el-input
              v-model="queryParams.keyword"
              clearable
              placeholder="账号/姓名/电话/邮箱"
              @keyup.enter="handleQuery"
            />
          </el-form-item>
          <el-form-item label="创建时间" prop="keyword">
            <el-date-picker
              v-model="queryParams.createTime"
              clearable
              end-placeholder="截止时间"
              range-separator="~"
              start-placeholder="开始时间"
              type="daterange"
              value-format="YYYY-MM-DD"
            />
          </el-form-item>
          <el-form-item label="店铺状态" prop="businessStatus">
            <el-select
              v-model="queryParams.businessStatus"
              :value-on-clear="4"
              clearable
              placeholder="选择店铺状态"
              style="width: 200px"
            >
              <el-option
                v-for="item in businessStatusOptions"
                :key="item.value"
                :label="item.label"
                :value="item.value"
              />
            </el-select>
          </el-form-item>
          <el-form-item>
            <el-button :icon="Search" type="primary" @click="handleQuery">
              搜索
            </el-button>
            <el-button :icon="Refresh" @click="handleReset">重置</el-button>
          </el-form-item>
        </el-row>
      </el-form>
    </el-card>
  </div>
</template>
<script lang="ts" setup>
import { defineEmits, defineProps, ref } from "vue";
import { Refresh, Search } from "@element-plus/icons-vue";
import { BusinessQueryParams } from "@/api";

const props = defineProps<{
  showSearch: boolean;
}>();

const init = {
  createTime: [],
  keyword: "",
  businessStatus: 4,
};
const businessStatusOptions = [
  {
    label: "禁用",
    value: 0,
  },
  {
    label: "审核中",
    value: 1,
  },
  {
    label: "审核失败",
    value: 2,
  },
  {
    label: "正常",
    value: 3,
  },
  {
    label: "全部",
    value: 4,
  },
];
//查询对象
const queryParams = ref<BusinessQueryParams>({ ...init });

const emit = defineEmits(["handleQuery", "handleReset"]);

//查询方法
function handleQuery() {
  //调用父级方法
  emit("handleQuery", queryParams.value);
}

//重置方法
function handleReset() {
  queryParams.value = { ...init };
  emit("handleReset");
}
</script>

<style lang="scss" scoped>
#noticeSearch {
  margin-bottom: 10px;
}
</style>
